<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.org/ui">
<h:head>
	<title>Purchase Requisition: Edit</title>
</h:head>

<h:body>

	<ui:composition template="/WEB-INF/templates/1000_layout.xhtml">
		<ui:param name="menuPurchaseRequisitionClass" value="selected" />

		<ui:define name="content">

			<h:form>
				<p:breadCrumb>
					<p:menuitem value="Purchase Requisition Home" url="main.xhtml" />
				</p:breadCrumb>
				<br/>
			</h:form>

			<p:fieldset id="fsMain" legend="Purchase Requisition">
				<h:form id="prForm">
					<ui:include
						src="/WEB-INF/templates/entity/purchaseRequisition.edit.xhtml">
						<ui:param name="bean"
							value="#{purchaseRequisitionBean.purchaseRequisition}" />
						<ui:param name="backingBean"
							value="#{purchaseRequisitionBean}" />
					</ui:include>
					
					<br />
					
					<!-- buttons OPEN status -->
					<p:commandButton value="Save" rendered="#{purchaseRequisitionBean.statusOpen}"
						update=":fsMain :fsAuditTrail"
						action="#{purchaseRequisitionBean.save}" />
						
					<p:commandButton value="Submit for Approval" rendered="#{purchaseRequisitionBean.statusOpen}" 
						update=":fsMain :fsAddItem :fsAuditTrail"
						action="#{purchaseRequisitionBean.submitForApproval}" />
					
					<!-- buttons PENDING status -->
					<p:commandButton value="Reopen" rendered="#{purchaseRequisitionBean.statusPending}" 
						update=":fsMain :fsAddItem :fsAuditTrail"
						action="#{purchaseRequisitionBean.reopen}" />
						
					<p:commandButton value="Approve" rendered="#{purchaseRequisitionBean.statusPending}" 
						update=":fsMain :fsAuditTrail"
						action="#{purchaseRequisitionBean.approve}" />
						
					<!-- buttons for APPROVED status -->
					<p:commandButton value="Create PO" rendered="#{purchaseRequisitionBean.statusApproved}" 
						update=":fsMain :fsAuditTrail"
						action="/po/main" />
						
				</h:form>
				<br />
				<h:form id="reqTableForm">
					<ui:include
						src="/WEB-INF/templates/entity/purchaseRequisition.itemRequest.table.xhtml">
						<ui:param name="backingBean" value="#{purchaseRequisitionBean}" />
					</ui:include>

				</h:form>

				<h:form id="reqTableDlgForm">
					<ui:include
						src="/WEB-INF/templates/entity/purchaseRequisition.itemRequest.table.dialog.xhtml" />
				</h:form>

			</p:fieldset>

			<br />

			<p:fieldset id="fsAddItem" legend="Add Item" toggleable="true" toggleSpeed="500"
				rendered="#{purchaseRequisitionBean.statusOpen}"
				collapsed="true">
				<h:form>
					<ui:include src="/WEB-INF/templates/entity/partUnit.table.xhtml">
						<ui:param name="ajaxRowSelectUpdate" value=":partUnitForm:partUnitDetail" />
						<ui:param name="ajaxRowSelectOnComplete" value="PF('partUnitDialog').show()" />
					</ui:include>
				</h:form>
				<h:form id="partUnitForm">
					<ui:include
						src="/WEB-INF/templates/entity/partUnit.table.dialog.xhtml" />
				</h:form>
			</p:fieldset>

			<br />
			<p:fieldset id="fsAuditTrail" legend="Audit Trail" toggleable="true" toggleSpeed="500"
				collapsed="true">
				<ui:include
					src="/WEB-INF/templates/entity/purchaseRequisition.audit.xhtml">
					<ui:param name="bean"
						value="#{purchaseRequisitionBean.purchaseRequisition}" />
				</ui:include>
			</p:fieldset>

		</ui:define>

	</ui:composition>
</h:body>
</html>